import {getCopySendItemsList,copySendItemSubmitSecond} from '@/api/api'
// import breadcrumb from '../../common/breadcrumb'
import PageTemplate from '@/components/common/PageTemplate'
export default {
    components:{
      PageTemplate
    },
    data() {
        return {
            brand:[
                {name: 'lang.workbench'},
                {name: 'lang.need_read_task'}
            ],
            hasIcon:true,
            tableList:[

            ],
            procPicUrl:process.env.PROCPIC_ROOT,
            currentPage: 1,
            total:0,
            pageSize:10,
            advSearch: 'ndt.advance_search',
            keysword:'',//关键字
            searchType:0,
            taskDes:'',
            procName:'',
            launcher:'',
            searchParams:{
                searchType:0,
            }
        }
    },
    methods: {
        //高级搜索展开与收缩
        advanceSearch : function(){
            if(this.advSearch == "ndt.advance_search"){
                this.advSearch = "ndt.return";
            }else{
                this.advSearch = "ndt.advance_search";
            }
        },
        //展示流程图
        showProcPic:function(row){
            window.open(this.procPicUrl+row.procInstID);
        },
        getNeedReadList:function(params){
            let _this = this;
            getCopySendItemsList(params).then((result) => {
                if(result.status == "200" && result.data.code == "0"){
                    let data = result.data.data.data;
                    let paging = data.Paging;
                    let list = data.ToDoTasks;
                    _this.currentPage = paging.startPage;
                    _this.pageSize = paging.pageSize;
                    _this.total = paging.totalCount;
                    _this.tableList = list;
                }else{
                    _this.$alert(result.data.msg,_this.$t('cm.tips'));
                }

            }).catch((err) => {
                _this.$alert(err,_this.$t('cm.tips'));
            });
        },
        //改变每页记录数
        changeSize:function(size){
            let params = {
                pageIndex:1,
                pageSize:size,
                searchType:this.searchType
            }
            if(this.searchType != 0){
                params = Object.assign(params,{"searchParams":this.searchParams});
            }
            this.getNeedReadList(params);
        },
        //改变当前页数
        changeCurrentPage:function(index){
            let params = {
                pageIndex:index,
                pageSize:this.pageSize,
                searchType:this.searchType
            }
            if(this.searchType != 0){
                params = Object.assign(params,{"searchParams":this.searchParams});
            }
            this.getNeedReadList(params);
        },
        //上一页
        prePage:function(index){
            let params = {
                pageIndex:index,
                pageSize:this.pageSize,
                searchType:this.searchType
            }
            if(this.searchType != 0){
                params = Object.assign(params,{"searchParams":this.searchParams});
            }
            this.getNeedReadList(params);
        },
        //下一页
        nextPage:function(index){
            let params = {
                pageIndex:index,
                pageSize:this.pageSize,
                searchType:this.searchType,    
            }
            if(this.searchType != 0){
                params = Object.assign(params,{"searchParams":this.searchParams});
            }
            this.getNeedReadList(params);
        },
        //待阅提交
        hasRead:function(row){
            let _this = this;
            this.$confirm(_this.$t('ndt.isHasRead'),_this.$t('cm.tips'),{
                confirmButtonText: _this.$t('te.confirm'),
                cancelButtonText: _this.$t('te.cancel'),
                cancelButtonClass: 'btn-second',
                confirmButtonClass: 'btn-default',
            }).then(function(){
                copySendItemSubmitSecond({comment:"已阅",workId:row.sn}).then((result) => {
                    if(result.status == "200" && result.data.code == "0"){
                        _this.initList();
                    }else{
                        _this.$alert(result.data.msg,_this.$t('cm.tips'));
                    }
                }).catch((err) => {
                    _this.$alert(err,_this.$t('cm.tips'));
                });                   
            })
        },
        //跳转到详情
        gotoDetails:function(item){
            item.isHasReadTask = true;
            this.$router.push({path:"/need_deal_task_details/"+item.procInstID,query:{obj:item}});
        },
        initList:function(){
            let params = {
                pageIndex:1,
                pageSize:10,
                searchType:0,
                type:1,
                t:Math.random()
            }
            this.getNeedReadList(params);
        },
        //普通搜索 this.searchType = 1
        commonSearch:function(){
            this.searchType = 1;
            this.searchParams = {
                "Folio":this.keysword
            }
            let params = {
                pageIndex:1,
                pageSize:this.pageSize,
                type:1,
                searchParams:{
                    "Folio":this.keysword
                },
                searchType:this.searchType
            }
            this.getNeedReadList(params);
        },
        advanSearch:function(){
            this.searchType = 2;
            this.searchParams = {
                "Folio":this.taskDes,
                "ProcessName":this.procName,
                "StartUserCN":this.launcher
            }
            let params = {
                pageIndex:1,
                pageSize:this.pageSize,
                type:1,
                searchParams:{
                    "Folio":this.taskDes,
                    "ProcessName":this.procName,
                    "StartUserCN":this.launcher
                },
                searchType:this.searchType
            }
            this.getNeedReadList(params);
        },
        //重置按钮操作
        reset(){
            this.taskDes = "";
            this.procName = "";
            this.launcher = "";
        }
    },
    mounted() {
        //mock 数据
        var _this = this;
        _this.tables = [];
        //searchType 表示不带任何条件的搜索,type = 1 表示列表搜索  2 表示快速审批
        let params = {
            pageIndex:1,
            pageSize:10,
            searchType:0,
            type:1,
            t:Math.random()
        }
        this.getNeedReadList(params);
    },
}